﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;
namespace NotebookS2
{
    public partial class PRNT_GRT : RibbonForm
    {
        public PRNT_GRT()
        {
            InitializeComponent();
        }
        public string ConnectionString { get; set; }
        public string DocumentNumber { get; set; }

        public string GetLayout()
        {
            ObjectTypeManager oManager = new ObjectTypeManager();
            const int _DOCUMENT_TYPE = 9;
            oManager.ConnectionString = this.ConnectionString;

            oManager.Open();

            string _FILE_NAME = oManager.GetPrintLayout1(_DOCUMENT_TYPE);

            oManager.Close();
            
            return _FILE_NAME;
        }

       

        public void Viewlayout(string sDocNumber)
        {
            ReportDocument rptDoc = new ReportDocument();
            SqlConnection oConnection = new SqlConnection();
            SqlCommand oCommand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            try
            {
                string sReportFile = GetLayout();

                rptDoc.Load(sReportFile);



                this.DocumentNumber = sDocNumber;

                oConnection.ConnectionString = this.ConnectionString;
                oConnection.Open();

                oCommand.Connection = oConnection;
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.CommandText = "SP_LAYOUT_GRT";

                oCommand.Parameters.Add(new SqlParameter("@DocNum", sDocNumber));
                oAdapter.SelectCommand = oCommand;
                oAdapter.Fill(ds);

                oConnection.Close();


                rptDoc.SetDataSource(ds.Tables[0]);
                CRViewer.ReportSource = rptDoc;
                CRViewer.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                rptDoc.Dispose();
                oConnection.Dispose();
                oCommand.Dispose();
                oAdapter.Dispose();
                ds.Dispose();
            }
        }
        private void PRNT_SO_Load(object sender, EventArgs e)
        {
            Viewlayout(this.DocumentNumber);
        }
    }
}
